<?php

namespace app\admin\controller;

use think\Controller;

class programe extends Controller
{
    //读取项目简介
    public function deploy(){
        $data = [
            'data' => '',
            'success' => false,
            'messages' => '读取失败'
        ];
        $system = model('Program')->where('id',1)->find();
        $system['file'] = json_decode($system['file']);
        if ($system){
            $data['success'] = true;
            $data['messages'] = '读取成功';
        }
        $data['data'] = $system;
        return json($data);

    }
    //读取项目介绍
    public function intro(){
        $data = [
            'data' => '',
            'success' => false,
            'messages' => '读取失败'
        ];

        $system = model('Program')->where('id',2)->find();
        if ($system){
            $system['file'] = json_decode($system['file']);
            $data['success'] = true;
            $data['messages'] = '读取成功';
        }
        $data['data'] = $system;
        return json($data);

    }
    //修改项目简介
    public function updateDeploy()
    {
        $return = [
            'success' => false,
            'messages' => '更新失败'
        ];

        $data = [
            'title' => input('put.title'),
            'defaulePageview' => input('put.defaulePageview'),
            'file' => json_encode(input('put.file')),
            'content' => input('put.content'),
            'author' =>input('put.author'),
            'update_time' =>time()
        ];
        $result = model('Program')->updateDeploy($data);
        if ($result) {
            $return['success'] = true;
            $return['messages'] = '更改成功';
        } else {
            $return['messages'] = $result;
        }


        return json($return);
    }

    //修改项目介绍
    public function updateIntro()
    {
        $return = [
            'success' => false,
            'messages' => '更新失败'
        ];

        $data = [
            'title' => input('put.title'),
            'defaulePageview' => input('put.defaulePageview'),
            'file' => json_encode(input('put.file')),
            'content' => input('put.content'),
            'author' =>input('put.author'),
            'update_time' =>time()

        ];
        $result = model('Program')->updateIntro($data);
        if ($result) {
            $return['success'] = true;
            $return['messages'] = '更改成功';
        } else {
            $return['messages'] = $result;
        }


        return json($return);
    }

}
